﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Web;
using Rotempco.Core.ORM.Objects;
using Rotempco.Core.ORM.Objects.Stores;

namespace Rotempco.Core.Logic
{
    public static class ThreadLogic
    {
        public static void RunInNewBlockingThread(Action action)
        {
            HttpContext currentSession = HttpContext.Current;
            bool done = false;
            new Thread(new ThreadStart(() =>
            {
                try
                {
                    HttpContext.Current = currentSession;
                    action();
                }
                finally
                {
                    done = true;
                }
            })).Start();

            while (!done)
                Thread.Sleep(1);
        }
    }
}
